package fleditor.view
{
	import flash.display.Sprite;
	import flash.display.Stage;
	import flash.events.Event;
	
	import fleditor.common.MapAssetLibLoad;
	import fleditor.controller.FlEditorController;
	import fleditor.events.FlEditorEvent;
	import fleditor.model.FlEditorModel;
	import fleditor.utils.GetSwfAllClass;
	
	import ui.top.topBarUI;

	/**
	 * 主界面视图 
	 * @author Devin
	 * 
	 */	
	public class MainView extends Sprite
	{
		/**
		 *舞台 
		 */		
		private var _stage:Stage;
		
		/**
		 *全局Model类(FlEditModel)
		 */		
		private var _model:FlEditorModel;
		
		/**
		 *全局控制器(FlEditorController) 
		 */		
		private var _controller:FlEditorController;
		
		/**
		 *顶部条视图 
		 */		
		private var _topBarView:TopBarView;
		
		/**
		 *物件编辑总视图 
		 */		
		private var _AssetView:AssetView;
		
		/**
		 * 主界面视图
		 * @param controller 全局controller类
		 * @param model 全局Model类
		 * 
		 */		
		public function MainView(stage:Stage, controller:FlEditorController, model:FlEditorModel)
		{
			_stage=stage;
			_controller=controller;
			_model=model;
			
			setView();//视图设置
			setEvent();
		}
		
		/**
		 * 视图设置 
		 */		
		private function setView():void
		{
			//创建顶部条视图并加载
			_topBarView=new TopBarView(_controller, _model);
			addChild(_topBarView);
		}
		
		/**
		 *事件设置 
		 * 
		 */		
		private function setEvent():void
		{
			_stage.addEventListener(Event.RESIZE, __onStageResize);
			_controller.addEventListener(FlEditorEvent.MENU_ACTION_TYPE, __onMenuAction);
		}
		
		/**
		 *设定当前功能视图（对应一级操作菜单） 
		 * @param evt
		 * 
		 */		
		private function __onMenuAction(evt:FlEditorEvent):void
		{
			switch(evt.date)
			{
				case 1://物件编辑
					if(!_AssetView) _AssetView=new AssetView(_stage, _controller, _model);
					_AssetView.y=_topBarView.height;
					_AssetView.x=3;
					addChild(_AssetView);
					break;
			}
		}
		
		/**
		 *当舞台窗口改变大小 
		 * @param evt
		 * 
		 */		
		private function __onStageResize(evt:Event):void
		{
			graphics.clear();
			graphics.lineStyle(1, 0x525252);
			graphics.moveTo(0, 61);
			graphics.lineTo(0, _stage.stageHeight-1);
			graphics.lineTo(_stage.stageWidth-1, _stage.stageHeight-1);
			graphics.lineTo(_stage.stageWidth-1, 61);
			
			graphics.lineStyle(1, 0xb1b1b1);
			graphics.moveTo(1, 60);
			graphics.lineTo(1, _stage.stageHeight-2);
			graphics.lineTo(_stage.stageWidth-2, _stage.stageHeight-2);
			graphics.lineTo(_stage.stageWidth-2, 60);
			
			graphics.lineStyle(1, 0x525252);
			graphics.moveTo(2, 59);
			graphics.lineTo(2, _stage.stageHeight-3);
			graphics.lineTo(_stage.stageWidth-3, _stage.stageHeight-3);
			graphics.lineTo(_stage.stageWidth-3, 59);
			
			graphics.endFill();
		}
		
		private function test():void
		{
			var load:MapAssetLibLoad=new MapAssetLibLoad("map/MapAsset.swf");
			load.addEventListener(Event.COMPLETE, __onMapAssetLibLoadComplete);
		}
		
		private function __onMapAssetLibLoadComplete(evt:Event):void
		{
			var load:MapAssetLibLoad=evt.currentTarget as MapAssetLibLoad;
			var arr:Array=GetSwfAllClass.getSWFClassName(load.assetLib);
		}
	}
}